<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();

class Admin_users extends Admin_Controller {

	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('User_model', 'users', TRUE);
		
		$this->load->helper('form');
	}
	
	public function index()
	{
		//$data['error'] 				= $this->input->post('error', TRUE);
		/*		
		$data['filter_id'] 			= $this->input->post('filter_id', TRUE);
		$data['filter_usr'] 		= $this->input->post('filter_usr', TRUE);
		$data['filter_email'] 		= $this->input->post('filter_email', TRUE);
		$data['filter_condition'] 	= $this->input->post('filter_condition', TRUE);
		$data['filter_wildcard'] 	= $this->input->post('filter_wildcard', TRUE);
		*/
		//print_r($data);
				
		$data['post'] 			= $this->input->post(NULL, TRUE);
		$data['users'] 			= $this->users->get_user_list($data['post']);
		$data['user_types'] 	= $this->users->get_user_types();
				
		$this->load->view('admin/user_list', $data);
	}
	
	public function insert()
	{
		$post = $this->input->post(NULL, false);
		
		if(! $this->users->insert_user($post))
		{
			$_POST['error'] = "can't create user";
		}
		
		header("Location:/admin/user");
	}
	
	public function switch_user_activation($id_user, $set_status)
	{
		$this->users->switch_user_status($id_user, 'is_active', $set_status);
		header("Location:/admin/user");
	}
	
	public function switch_user_lock($id_user, $set_status)
	{
		$this->users->switch_user_status($id_user, 'is_blocked', $set_status);
		header("Location:/admin/user");
	}
	
	public function edit($id_user)
	{
		$data['user'] = $this->users->get_user_by_id($id_user);
		$this->load->view('/admin/user_edit', $data);
	}
	
	public function delete($id_user)
	{
		$this->users->get_user_by_id($id_user);
		$this->load->view('/admin/user_list');
	}
}

/* End of file admin_users.php */
/* Location: ./application/controllers/admin/admin_users.php */